package com.jie.jie.ShortCut;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.jie.jie.MainActivity;
import com.jie.jie.R;

import java.lang.reflect.Method;

public class ShortCutActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_short_cut);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
//                if (ShortCutUtils.hasShortcut(ShortCutActivity.this)) {
//                    ShortCutUtils.delShortcut(ShortCutActivity.this);
//                } else {
//                    ShortCutUtils.addShortcut(ShortCutActivity.this,R.mipmap.a1);
//                }
//                changeIcon();

                try {

                    Class<Bundle> bundleClass = Bundle.class;
                    Bundle bundle = bundleClass.newInstance();
                    Class<MainActivity> mainActivityClass = MainActivity.class;
                    Method onRestarts = mainActivityClass.getDeclaredMethod("onCreate",Bundle.class);
                    onRestarts.invoke(mainActivityClass.newInstance(),bundle);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                }
            }
        });

    }
//    private void changeIcon(){
//        PackageManager pm = getApplicationContext().getPackageManager();
//        System.out.println(getComponentName());
//        //去除旧图标，不去除的话会出现2个App图标
//        pm.setComponentEnabledSetting(getComponentName(),
//                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
//                PackageManager.DONT_KILL_APP);
//        //显示新图标
//        pm.setComponentEnabledSetting(new ComponentName(
//                        getBaseContext(),
//                        "com.jie.jie.mvp.ui.MVPActivity"),
//                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
//                PackageManager.DONT_KILL_APP);
//    }



}
